package com.yyk.yykywd.network

import com.jakewharton.retrofit2.adapter.kotlin.coroutines.CoroutineCallAdapterFactory
import com.yyk.yiliao.bean.UserbankUsersInfo
import com.yyk.yiliao.util.rx.ApiService
import kotlinx.coroutines.Deferred
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.FieldMap
import retrofit2.http.FormUrlEncoded
import retrofit2.http.POST

private val okHttpClient: OkHttpClient = OkHttpClient.Builder()
        .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
        .build()

private val retrofit = Retrofit.Builder()
        .addConverterFactory(GsonConverterFactory.create())
        .addCallAdapterFactory(CoroutineCallAdapterFactory())
        .baseUrl(ApiService.BASE_URL)
        .client(okHttpClient)
        .build()

interface BusinessApiService {
    @FormUrlEncoded
    @POST("mobile/userbank/users")
    fun getUserInfo(@FieldMap stringMap: Map<String, String>): Deferred<UserbankUsersInfo>
}

object BusinessApi {
    val retrofitService: BusinessApiService by lazy {
        retrofit.create(BusinessApiService::class.java)
    }
}